<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
<style type="text/css">
	.item{
		width: 115px;
		display: inline-block;
		margin-left: 5px;
	}
    </style>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	  <table style="width:100%;">
	  	<tr>
	  		<td style="width:30%;">
	  		  <span class="item">短信类型：</span>
	  		  <input id="sms_type" showNullItem="true" emptyText="请选择..." nullItemText="全部" class="mini-combobox" style="width:160px;" textField="keyValue" valueField="keyName" url="dictionary_cm_key_val_view.do?typeName=SMS_PHRASE_TYPE" />
        	</td>
        	<td style="width:30%;">
	  		  <span class="item">添加时间（开始）：</span>	
        	  <input id="startTime" class="mini-datepicker" allowInput="false" emptyText="请选择..." style="width:160px;" format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" allowIput="false" />
        	</td>
        	<td style="width:30%;">
	  		  <span class="item">添加时间（截止）：</span>		
	  		  <input id="endTime" class="mini-datepicker" allowInput="false" emptyText="请选择..." style="width:160px;" format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" allowIput="false" />
	  		</td>
	  		<td style="white-space:nowrap;">
           		<a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
            </td>
	  	</tr>
	  </table>
	  </div>
	  <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	   <table>
		<tr>
			<td>
				<sec:authorize url='/sms_phrase_add.do'>
			    <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
			    </sec:authorize>
			    <sec:authorize url='/sms_phrase_edit.do'>
			    <a class="mini-button" iconCls="icon-edit" onclick="edit()">修改</a>
			    </sec:authorize>
			    <sec:authorize url='/sms_phrase_delete.do'>
		        <a class="mini-button" iconCls="icon-remove" onclick="remove()">批量删除</a>
		        </sec:authorize>
			</td>
		</tr>
	</table>
	</div>
	<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20" url="sms_common_settings_view.do" multiSelect="true" style="width:100%;height:100%;">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div type="checkcolumn" checked="false" ></div>
			<div field="content" width="35%" headerAlign="center" align="center">短信内容</div>
			<div field="typeKV" width="25%" headerAlign="center" align="center">短信类型</div>
			<div field="createTime" width="20%" headerAlign="center" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss" align="center">添加时间</div>
			<div field="updateTime" width="20%" headerAlign="center" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss" align="center">修改时间</div>
		</div>
	</div>
	</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();

function search() {
	var sms_type = mini.get("sms_type").getFormValue();
    var startTime = mini.get("startTime").getFormValue();
    var endTime = mini.get("endTime").getFormValue();
    grid.load({ type: sms_type,
    	stime: startTime,
    	etime: endTime
    });
}


//添加
function add() {
    mini.open({
        url: "sms_phrase_add.do",
        allowResize:false,
        title: "添加", width: 540, height: 350,
        ondestroy: function (action) {
        	if(action == 'succ'){
        		mini.showMessageBox({
                    title: "提示",
                    showModal:false,
                    iconCls: "mini-messagebox-info",
                    message: "添加成功！",
                    timeout: 3000,
                    x: 'right',
                    y: 'bottom'
                });
            	grid.reload();
        	}
        }
    });
}

//修改
function edit() {
    var row = grid.getSelecteds();
    if (row.length == 1) {
        mini.open({
            url: "sms_phrase_edit.do",
            allowResize:false,
            title: "修改", width: 540, height: 350,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {row: row[0] };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
            	if(action == 'succ'){
            		mini.showMessageBox({
                        title: "提示",
                        showModal:false,
                        iconCls: "mini-messagebox-info",
                        message: "修改成功！",
                        timeout: 3000,
                        x: 'right',
                        y: 'bottom'
                    });
                	grid.reload();
            	}
            }
        });
        
    } else {
    	mini.alert("请选中一条记录");
    }
}

//删除
function remove() {
	var rows = grid.getSelecteds();
    if (rows.length > 0) {
    	mini.confirm("确定删除选中记录？", "删除",function(result){
    		if(result == "ok"){
    			 var ids = [];
    		        for (var i = 0, l = rows.length; i < l; i++) {
    		            var r = rows[i];
    		            ids.push(r.id);
    		        }
    		        var id = ids.join(',');
    		        grid.loading("操作中，请稍后......");
    		        $.ajax({
    		            url: "sms_phrase_delete.do?ids=" +id,
    		            success: function (text) {
    		                grid.reload();
    		            }
    		        });
    			}
    	},"json");
    } else {
  	  mini.alert("请选中一条记录");
    }
}
</script>
</body>
</html>